<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-header">
        <h2 class="logo">Becho</h2>
        <p class="subtitle">欢迎回来</p>
      </div>
      <a-form
        :model="formState"
        name="login"
        class="login-form"
        @finish="onFinish"
        @finishFailed="onFinishFailed"
      >
        <a-form-item
          name="username"
          :rules="[{ required: true, message: '请输入用户名' }]"
        >
          <a-input
            v-model:value="formState.username"
            placeholder="用户名"
            size="large"
          >
            <template #prefix>
              <user-outlined />
            </template>
          </a-input>
        </a-form-item>

        <a-form-item
          name="password"
          :rules="[{ required: true, message: '请输入密码' }]"
        >
          <a-input-password
            v-model:value="formState.password"
            placeholder="密码"
            size="large"
          >
            <template #prefix>
              <lock-outlined />
            </template>
          </a-input-password>
        </a-form-item>

        <div class="form-footer">
          <a-checkbox v-model:checked="formState.remember">记住我</a-checkbox>
          <a class="forgot-link">忘记密码？</a>
        </div>

        <a-form-item>
          <a-button
            type="primary"
            html-type="submit"
            class="login-button"
            size="large"
            :loading="loading"
          >
            登录
          </a-button>
        </a-form-item>

        <div class="divider">
          <span>或</span>
        </div>

        <div class="social-login">
          <a-button class="social-button wechat">
            <template #icon><wechat-outlined /></template>
            微信登录
          </a-button>
          <a-button class="social-button weibo">
            <template #icon><weibo-outlined /></template>
            微博登录
          </a-button>
        </div>

        <div class="register-link">
          还没有账号？<a>立即注册</a>
        </div>
      </a-form>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { message } from 'ant-design-vue';
import {
  UserOutlined,
  LockOutlined,
  WechatOutlined,
  WeiboOutlined
} from '@ant-design/icons-vue';

interface FormState {
  username: string;
  password: string;
  remember: boolean;
}

const formState = reactive<FormState>({
  username: '',
  password: '',
  remember: true
});

const loading = ref<boolean>(false);

const onFinish = async (values: FormState) => {
  loading.value = true;
  try {
    // 这里添加实际的登录逻辑
    console.log('Success:', values);
    message.success('登录成功');
  } catch (error) {
    message.error('登录失败，请重试');
  } finally {
    loading.value = false;
  }
};

const onFinishFailed = (errorInfo: any) => {
  console.log('Failed:', errorInfo);
};
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #95C7E0 0%, #6893AC 100%);
}

.login-box {
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.logo {
  font-size: 32px;
  font-weight: bold;
  color: #6893AC;
  margin: 0;
}

.subtitle {
  color: #8c8c8c;
  margin-top: 8px;
}

.login-form {
  width: 100%;
}

.form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.forgot-link {
  color: #6893AC;
  cursor: pointer;
}

.forgot-link:hover {
  color: #95C7E0;
}

.login-button {
  width: 100%;
  background: #6893AC;
  border-color: #6893AC;
}

.login-button:hover {
  background: #95C7E0;
  border-color: #95C7E0;
}

.divider {
  position: relative;
  text-align: center;
  margin: 24px 0;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 45%;
  height: 1px;
  background: #f0f0f0;
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.divider span {
  background: white;
  padding: 0 8px;
  color: #8c8c8c;
}

.social-login {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.social-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.wechat {
  background: #07C160;
  border-color: #07C160;
  color: white;
}

.wechat:hover {
  background: #06AE56;
  border-color: #06AE56;
}

.weibo {
  background: #E6162D;
  border-color: #E6162D;
  color: white;
}

.weibo:hover {
  background: #D41528;
  border-color: #D41528;
}

.register-link {
  text-align: center;
}

.register-link a {
  color: #6893AC;
  cursor: pointer;
}

.register-link a:hover {
  color: #95C7E0;
}
</style>